import { Vue, Component, Prop, Emit, Ref } from 'vue-property-decorator'

@Component
export default class ModalMixins extends Vue {
  visible = false

  resolve: ((value?: any) => void) | null = null

  reject: ((value?: any) => void) | null = null

  submitting = false

  set actualVisible (value: boolean) {
    this.cancel()
  }

  get actualVisible () {
    return this.visible
  }

  cancel (args?: any) {
    this.visible = false
    if (this.reject) this.reject(args)
  }

  complete (args?: any) {
    this.visible = false
    if (this.resolve) this.resolve(args)
  }

  init<T> (): Promise<T> {
    this.visible = true
    return new Promise((resolve, reject) => {
      this.resolve = resolve
      this.reject = reject
    })
  }
}
